home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Memory / MemInit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  3.2 KB  |  144 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MemInit.cpp
  3.  
  4.     Contains:    CFM initializtion for Memory
  5.  
  6.     Owned by:    A. Michael Burbidge
  7.  
  8.     Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     7/11/96    jpa        1364000: Initial heap size = 16k since
  13.                                     system process doesn't need anything
  14.                                     larger.
  15.         <16>      6/7/95    jpa        Removed old (pre-SLIM) SOM includes.
  16.                                     [1256901]
  17.         <15>      6/2/95    TJ        Included Gestalt.h
  18.         <14>      6/1/95    jpa        Restored <12>: Compute total system memory
  19.                                     at init time [1249619]
  20.         <13>     5/17/95    TJ        Backed out changes from previous checkin.
  21.         <11>     1/12/95    jpa        Strings.h --> TextUtils.h [1210936]
  22.         <10>     12/5/94    jpa        Nuked errant pragma lib_export's. [1195676]
  23.          <9>    10/24/94    jpa        Turn off validation
  24.          <8>    10/11/94    NP        1189812: Make Init routine pascal.
  25.          <7>     9/29/94    RA        1189812: Mods for 68K build.
  26.          <6>     9/14/94    jpa        Don't include UseRsrcM.h [1186692]
  27.          <5>      9/9/94    jpa        Added prototype & commented out initBlkPtr
  28.                                     to avoid warnings.
  29.          <4>     8/19/94    jpa        Call ODInitMemory at library init time
  30.                                     [1182106]
  31.          <3>     6/30/94    jpa        Added InitLibraryResources call.
  32.          <2>     6/23/94    NP        Clean up.
  33.          <1>     6/10/94    MB        first checked in
  34.     To Do:
  35.     In Progress:
  36.         
  37. */
  38.  
  39.  
  40. #ifndef __CODEFRAGMENTS__
  41. #include <CodeFragments.h>
  42. #endif
  43.  
  44. #ifndef _MEMMGR_
  45. #include "MemMgr.h"
  46. #endif
  47.  
  48. #ifndef _MEMDEBG_
  49. #include "MemDebg.h"
  50. #endif
  51.  
  52. #ifndef _MEMMGRPV_
  53. #include "MemMgrPv.h"
  54. #endif
  55.  
  56. #ifndef __GESTALT__
  57. #include <Gestalt.h>
  58. #endif
  59.  
  60. #ifndef __ERRORS__
  61. #include <Errors.h>
  62. #endif
  63.  
  64. #ifndef __PROCESSES__
  65. #include <Processes.h>
  66. #endif
  67.  
  68. #ifndef __TEXTUTILS__
  69. #include <TextUtils.h>
  70. #endif
  71.  
  72. #ifndef __SOM__
  73. #include <som.xh>
  74. #endif
  75.  
  76.  
  77. MMBoolean gHaveSOM;
  78.  
  79. size_t gTotalMemory;                // Declared in PlatfMem.h
  80.  
  81.  
  82. static OSErr
  83. GetProcessName( char name[] )
  84. {
  85.     name[0] = 0;
  86.     
  87.     ProcessSerialNumber psn;
  88.     psn.highLongOfPSN = 0;
  89.     psn.lowLongOfPSN = kCurrentProcess;
  90.     
  91.     ProcessInfoRec info;
  92.     info.processInfoLength = sizeof(info);
  93.     info.processName = (StringPtr) name;
  94.     info.processAppSpec = kMMNULL;
  95.     OSErr err= GetProcessInformation(&psn,&info);
  96.     if( !err )
  97.         p2cstr((StringPtr)name);
  98.     return err;
  99. }
  100.  
  101.  
  102. extern "C" {
  103.     pascal OSErr MemoryCFMInit( CFragInitBlockPtr );
  104.     static void* MMCAllocate( size_t size, size_t n );
  105. }
  106.  
  107. static void* MMCAllocate( size_t size, size_t n )
  108. {
  109.     return MMAllocateClear(n*size);
  110. }
  111.  
  112.  
  113. pascal OSErr MemoryCFMInit( CFragInitBlockPtr )
  114. {
  115. #if MM_DEBUG
  116.     long result;
  117.     if( Gestalt(gestaltLogicalRAMSize,(long*)&gTotalMemory) != noErr )
  118.         gTotalMemory = 0x80000000;    // bogus default value
  119.     if( Gestalt(gestaltVMAttr,&result) == noErr && (result&1) )
  120.         gTotalMemory <<= 1;            // Use double logical RAM size if VM on
  121.                                     // since code fragments get loaded above it
  122. #endif
  123.  
  124.     // Create a default heap:
  125.     char name[256];
  126.     GetProcessName(name);
  127.     strcat(name," default heap"); // For debugging only so hardcoded string is OK
  128.     MemHeap *heap = MMNewHeap(kMMTempMemory,16*1024L,32*1024L,name);
  129.     if( !heap )
  130.         return memFullErr;
  131.     MMSetDefaultHeap(heap);
  132.     
  133.     gHaveSOM = ((void*)&SOMMalloc != (void*)kUnresolvedCFragSymbolAddress);    // Is SOM installed?
  134.  
  135.     if( gHaveSOM ) {
  136.         SOMMalloc = &MMAllocate;
  137.         SOMCalloc = &MMCAllocate;
  138.         SOMRealloc= &MMReallocate;
  139.         SOMFree   = &MMFree;
  140.     }
  141.  
  142.     return noErr;
  143. }
  144.